package com.yanyilu.qiubite.jpa;

import com.yanyilu.qiubite.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface UserJpa extends JpaRepository<User,Integer> {

    @Query(value = "select * from user where spot_id = :spotId",nativeQuery = true)
    List<User> spotUserList(@Param("spotId") Integer spotId);

    @Query(value = "select * from user",nativeQuery = true)
    List<User> adminUserList();

    @Query(value = "select * from user where prize_code = :prizeCode",nativeQuery = true)
    User prizeCodeByUser(@Param("prizeCode") String prizeCode);

    @Query(value = "select * from user where spot_id = :spotId and phone_number = :phoneNumber",nativeQuery =true)
    User findByPhoneAndSpotId(@Param("spotId")Integer spotId, @Param("phoneNumber")String phoneNumber);

    @Query(value = "select s.app_id from spot s left join user u on u.spot_id = s.spot_id where u.user_id = :userId  ",nativeQuery = true)
    String findAppId(@Param("userId") Integer userid);
}
